<?php
if(!defined('SYSTEM_PATH')) die('Cannot access this page directly or see your configuration file ') ;
/**
 * Benchmark
 *
 * Gestion des benchmarks
 *
 * @package cosmoClan
 * @author menTiss - Staff SeS
 * @copyright 2007-2008
 * @version 0.1.0
 * @access public
 **/
 class Benchmark extends Cosmo {
 	private $_marker 	= array() ;
 	private $_save 	= array() ;

 	public function setMarker($name) {
 		if(!is_string($name))
 			return false;
 		if(isset($this->_marker[$name]['begin']) && isset($this->_marker[$name]['end']))
 			return true;
 		if(isset($this->_marker[$name]['begin']))
 			$this->_marker[$name]['end'] = microtime() ;
 		else
 			$this->_marker[$name]['begin'] = microtime() ;
	}
	public function getBench($name, $save = false) {
		if(isset($this->_marker[$name])) {
			$res = bcsub($this->_marker[$name]['begin'], $this->_marker[$name]['end'], 4) ;
			if($save === true) {
				$this->saveTime($name, bcadd($res, $this->getTime($name), 4)) ;
			}
			return $res ;
		}
	}
	public function saveTime($name,$time) {
		if(is_string($name) && is_numeric($time)) {
			$this->_save[$name] = $time ;
		}
	}
	public function getTime($name) {
		if(is_string($name) && isset($this->_save[$name])) {
			return $this->_save[$name] ;
		}
		return 0 ;
	}
 }

?>